//
//  ViewController.m
//  裁切图片2
//
//  Created by hyl on 16/6/27.
//  Copyright © 2016年 hyl. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImage *image=[UIImage imageNamed:@"阿狸头像"];
    CGSize s=CGSizeMake(image.size.width+2, image.size.height+2);
    UIGraphicsBeginImageContextWithOptions(s, NO, 0);
    UIBezierPath *path=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width+2, image.size.height+2)];
    [[UIColor redColor]set];
    [path fill];
    //注意裁切的圆起始点变了
    UIBezierPath *clipPath=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(1, 1, image.size.width, image.size.height)];
    [clipPath addClip];
    [image drawAtPoint:CGPointZero];
    UIImage *image1=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    _imageView.image=image1;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
